<template>
  <div class="header">
    <div class="mylogo">
      <img src="../assets/yunlogo.png" alt="yunlogo">
      <span>寻真云盘</span>
    </div>
    <div class="rcontent">
      <el-dropdown>
        <span class="el-dropdown-link">
          <span>{{ username }}</span>
          <img class="userhead" src="../assets/head.png" alt="head">
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="logout()">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>

    </div>
  </div>
</template>
<script>
import Cookie from 'js-cookie'
import MGTAPI from '@/api/management';
export default {
  data() {
    return {
      username: ''
    };
  },
  methods: {
    selectUserName() {
      MGTAPI.getAdminInformation().then(res => {
        if (res.data.code == 0) {
          this.$message.error(res.data.msg)
          return
        }
        console.log(res.data.data)
        this.username = res.data.data
      })
    },
    logout() {
      MGTAPI.loginoutApi().then(() => {
        Cookie.remove("token");
        this.$router.push("/login")
      })
    },
  },
  created() {
    //自动加载indexs方法
    this.selectUserName();
  },
};
</script>
  
<style lang="less" scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 80px;
  background-color: #ffffff;
}

.mylogo {
  margin-left: 20px;
  display: flex;
  align-items: center;

  img {
    vertical-align: middle;
    width: 70px;
    height: 70px;
  }

  span {
    vertical-align: middle;
    font-size: xx-large;
    color: #d3cfcf;
    text-align: center;
    font-weight: bold;
    font-family: 'Zhi Mang Xing';
    margin-left: 10px;
  }
}

.rcontent {
  margin-right: 20px;
  display: flex;
  align-items: center;

  .userhead {
    vertical-align: middle;
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }

  span {
    margin-right: 10px;
    font-size: 16px;
    color: rgb(229, 229, 229);
  }
}
</style>
  